package books;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.joda.time.DateTime;

import util.Entity;
import builders.BookInfoBuilder;

/**
 * Represents the specifications of a book.
 */
public class BookInfo extends Entity {

    private static final long serialVersionUID = 1L;

    private String title;

    private String isbn;

    private String description;

    private DateTime registrationDate;

    private Publisher publisher;

    private List<Author> authors;

    private List<Category> categories;

    private boolean available;

    public BookInfo(final String aTitle, final String aIsbn, final String aDecription, final Publisher aPublisher,
            final List<Author> anAuthors, final List<Category> aCategories) {

        super();

        this.title = aTitle;
        this.isbn = aIsbn;
        this.description = aDecription;
        this.publisher = aPublisher;
        this.authors = anAuthors;
        this.categories = aCategories;
        this.registrationDate = DateTime.now();
        this.available = true;
    }

    public BookInfo() {
        super();
        this.authors = new ArrayList<Author>();
        this.categories = new ArrayList<Category>();
        this.registrationDate = DateTime.now();
        // empty constructor
    }

    public BookInfo(final BookInfoBuilder bookInfoBuilder) {
        super();
        this.title = bookInfoBuilder.getTitle();
        this.description = bookInfoBuilder.getDescription();
        this.authors = bookInfoBuilder.getAuthors();
        this.categories = bookInfoBuilder.getCategories();
        this.isbn = bookInfoBuilder.getIsbn();
        this.available = bookInfoBuilder.isAvailable();
        this.registrationDate = bookInfoBuilder.getRegistrationDate();
        this.publisher = bookInfoBuilder.getPublisher();
    }

    public DateTime getRegistrationDate() {
        return this.registrationDate;
    }

    public void setRegistrationDate(final DateTime registrationDate) {
        this.registrationDate = registrationDate;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(final String aTitle) {
        this.title = aTitle;
    }

    public String getIsbn() {
        return this.isbn;
    }

    public void setIsbn(final String anIsbn) {
        this.isbn = anIsbn;

    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(final String aDescription) {
        this.description = aDescription;
    }

    public Publisher getPublisher() {
        return this.publisher;
    }

    public void setPublisher(final Publisher aPublisher) {
        this.publisher = aPublisher;
    }

    public List<Author> getAuthors() {
        return this.authors;
    }

    public void setAuthors(final List<Author> anAuthors) {
        this.authors = anAuthors;
    }

    public void setCategories(final List<Category> aCategories) {
        this.categories = aCategories;
    }

    public List<Category> getCategories() {
        return this.categories;
    }

    public void setAvailable(final boolean bool) {
        this.available = bool;
    }

    public boolean isAvailable() {
        return this.available;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 31).append(this.getIsbn()).toHashCode();
    }

    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != this.getClass()) {
            return false;
        }

        BookInfo rhs = (BookInfo) obj;
        return new EqualsBuilder().append(this.getIsbn(), rhs.getIsbn()).isEquals();
    }

}
